﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string userid = textBox1.Text;
            string username = textBox2.Text;
            string password = textBox3.Text;
            using (SqlConnection connection=new SqlConnection(SqlHelper.Constr))
            {
                connection.Open();
                string query = "insert into [user](userid,username,password,level)values(@userid,@username,@password,'1');";
                using(SqlCommand command=new SqlCommand(query,connection))
                {
                    try
                    {
                        command.Parameters.AddWithValue("@userid", userid);
                        command.Parameters.AddWithValue("@username", username);
                        command.Parameters.AddWithValue("@password", password);
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
